﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Web.Configuration;

namespace TeamFoundation.EventBus
{
    public partial class Install : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            bool isInstalled = WebConfigurationManager.AppSettings["isInstalled"] == "true";
            if (isInstalled || !User.IsInRole("Administrators"))
                Response.Redirect("Default.aspx");
        }

        protected void _installButton_Click(object sender, EventArgs e)
        {
            StringBuilder url = new StringBuilder("Action.ashx?type=InstallAction");
            url.AppendFormat("&dbServer={0}", Server.UrlEncode(_dbServer.Text));
            url.AppendFormat("&dbName={0}", Server.UrlEncode(_dbName.Text));
            url.AppendFormat("&tfServer={0}", Server.UrlEncode(_tfServer.Text));
            url.AppendFormat("&tfAccount={0}", Server.UrlEncode(_tfAccount.Text));
            url.AppendFormat("&dbCreate={0}", _dbCreate.Checked ? "true" : "false");
            url.AppendFormat("&dbTables={0}", _dbTables.Checked ? "true" : "false");

            Response.Redirect(url.ToString());
        }
    }
}
